﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using KNXFramework;
using KNXFramework.KNXObjects;

namespace KNXService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "KNXObjectsManager" in code, svc and config file together.
    public class KNXObjectsManager : IKNXObjectsManager
    {

        public bool StartConnection()
        {
            return KNXConnectionContainer.StartConnection();
        }

        void m_ObjectController_OnKNXObjectUpdate(string id, string newValue)
        {
            //m_CallbackInstance.UpdateKNXObjectValue(id, newValue);
        }


        public void CloseConnection()
        {
            KNXConnection connection = KNXConnectionContainer.GetConnection();
            if (connection != null)
                connection.CloseConnection();
        }

        public KNXObject ReadValue(string id)
        {
            return new KNXObject(KNXConnectionContainer.GetController()[id]);
        }

        public void WriteValue(string id, string value)
        {
            KNXConnectionContainer.GetController()[id].SetObjectValue(value);
        }

        public Dictionary<string, KNXObject> GetAllObjects()
        {
            Dictionary<string, KNXObject> outputList = new Dictionary<string, KNXObject>(KNXConnectionContainer.GetController().Count);
            foreach (KNXObjectBase baseObj in KNXConnectionContainer.GetController().Values)
            {
                outputList.Add(baseObj.ID, new KNXObject(baseObj));
            }
            return outputList;
        }


    }
}
